package com.linkin.homepage.view.refresh.headerview;


import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.util.AttributeSet;

import com.linkin.homepage.base.autolayout.layout.AutoRelativeLayout;
import com.linkin.homepage.view.refresh.smallrefreshlayout.RefreshHeader;
import com.linkin.homepage.view.refresh.smallrefreshlayout.RefreshState;
import com.linkin.homepage.view.refresh.smallrefreshlayout.RefreshStyle;
import com.linkin.homepage.view.refresh.smallrefreshlayout.SmallRefreshLayout;


public class RefreshHeaderView extends AutoRelativeLayout implements RefreshHeader {

    public RefreshHeaderView(Context context) {
        super(context);
    }

    public RefreshHeaderView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public RefreshHeaderView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public RefreshHeaderView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    public int getStyle() {
        return RefreshStyle.CLASSIC;
    }

    @Override
    public void onMoving(SmallRefreshLayout refreshLayout, int state, int offset, int headerHeight, int maxDragHeight) {
    }

    @Override
    public void onStateChanged(SmallRefreshLayout refreshLayout, int state, int oldState) {
        AnimationDrawable animationDrawable = (AnimationDrawable) getChildAt(0).getBackground();
        if (state > RefreshState.DEFAULT) {
            if (!animationDrawable.isRunning()) {
                animationDrawable.start();
            }
        } else {
            animationDrawable.stop();
        }
    }
}
